package com.flxz.forum.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flxz.common.annotation.Log;
import com.flxz.common.core.controller.BaseController;
import com.flxz.common.core.domain.AjaxResult;
import com.flxz.common.enums.BusinessType;
import com.flxz.forum.domain.ForumCategory;
import com.flxz.forum.service.IForumCategoryService;
import com.flxz.common.utils.poi.ExcelUtil;
import com.flxz.common.core.page.TableDataInfo;

/**
 * 讨论分类Controller
 * 
 * @author fl
 * @date 2025-09-14
 */
@RestController
@RequestMapping("/forum/category")
public class ForumCategoryController extends BaseController
{
    @Autowired
    private IForumCategoryService forumCategoryService;

    /**
     * 查询讨论分类列表
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('forum:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForumCategory forumCategory)
    {
        startPage();
        List<ForumCategory> list = forumCategoryService.selectForumCategoryList(forumCategory);
        return getDataTable(list);
    }

    /**
     * 导出讨论分类列表
     */
    @PreAuthorize("@ss.hasPermi('forum:category:export')")
    @Log(title = "讨论分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumCategory forumCategory)
    {
        List<ForumCategory> list = forumCategoryService.selectForumCategoryList(forumCategory);
        ExcelUtil<ForumCategory> util = new ExcelUtil<ForumCategory>(ForumCategory.class);
        util.exportExcel(response, list, "讨论分类数据");
    }

    /**
     * 获取讨论分类详细信息
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('forum:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(forumCategoryService.selectForumCategoryByCategoryId(categoryId));
    }

    /**
     * 新增讨论分类
     */
    @PreAuthorize("@ss.hasPermi('forum:category:add')")
    @Log(title = "讨论分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumCategory forumCategory)
    {
        return toAjax(forumCategoryService.insertForumCategory(forumCategory));
    }

    /**
     * 修改讨论分类
     */
    @PreAuthorize("@ss.hasPermi('forum:category:edit')")
    @Log(title = "讨论分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumCategory forumCategory)
    {
        return toAjax(forumCategoryService.updateForumCategory(forumCategory));
    }

    /**
     * 删除讨论分类
     */
    @PreAuthorize("@ss.hasPermi('forum:category:remove')")
    @Log(title = "讨论分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(forumCategoryService.deleteForumCategoryByCategoryIds(categoryIds));
    }
}
